package com.guigu.service.impl;

import com.guigu.mapper.MemberexaminationMapper;
import com.guigu.mapper.OrderMapper;
import com.guigu.mapper.OrdersettingMapper;
import com.guigu.pojo.Memberexamination;
import com.guigu.pojo.Order;
import com.guigu.pojo.Ordersetting;
import com.guigu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper mapper;

    @Autowired
    MemberexaminationMapper mm;
    @Autowired
    OrdersettingMapper dd;
    @Override
    public int insert(Order record) {
        Order order = mapper.OrderDate(record);
        if (order==null){
             mapper.insert(record);


                Ordersetting ordersetting = dd.selectByPrimaryKey(record.getOrderdate());
                ordersetting.setReservations(ordersetting.getReservations()+1);
                dd.updateByPrimaryKey(ordersetting);

                Memberexamination memberexamination = new Memberexamination();
                memberexamination.setExamdate(record.getOrderdate());
                memberexamination.setMemberid(record.getMembeid());
                memberexamination.setSetmealid(record.getSetmealid());
                return   mm.insert(memberexamination);

        }else {
            Memberexamination select = mm.select(record);
            if (select==null){
                Memberexamination memberexamination = new Memberexamination();
                memberexamination.setExamdate(record.getOrderdate());
                memberexamination.setMemberid(record.getMembeid());
                memberexamination.setSetmealid(record.getSetmealid());
                return   mm.insert(memberexamination);
            }
            return -1;
        }

    }



    @Override
    public Ordersetting yyorderSetting(String date) {
        return dd.selectByPrimaryKey(date);
    }
}
